#include <cstdio>

int n, m, s[ 1100001 ];
bool visit[ 1100001 ];

int find( int root )
{
    if ( s[ root ] == -1 )
        return root;
    return s[ root ] = find( s[ root ] );
}

void unionSet( int root1, int root2 )
{
    root1 = find( root1 );
    root2 = find( root2 );
    if ( root1 != root2 )
        s[ root2 ] = root1;
}

void work( )
{
    int i, j, t, x, y, p, cnt = 0, nm[ 100001 ], e = n;
    char cmd[ 2 ];
    for ( i = 0; i < n + m; i++ )
    {
        visit[ i ] = false;
        s[ i ] = -1;
    }
    for ( i = 0; i < n; i++ )
        nm[ i ] = i;
    for ( i = 0; i < m; i++ )
    {
        scanf("%s", cmd);
        if ( cmd[ 0 ] == 'M' )
        {
            scanf("%d%d", &x, &y);
            unionSet( nm[ x ], nm[ y ] );
        }
        else
        {
            scanf("%d", &t);
            nm[ t ] = e++;
        }
    }
    for ( i = 0; i < n; i++ )
        if ( !visit[ find( nm[ i ] ) ] )
        {
            cnt++;
            visit[ find( nm[ i ] ) ] = true;
        }
    printf("%d\n", cnt);
}

int main( )
{
    int scase = 1;
    while ( scanf("%d%d", &n, &m) )
    {
        if ( n == 0 && m == 0 )
            break;
        printf("Case #%d: ", scase++);
        work( );
    }
    return 0;
}
